<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改用户')" />
    <th:block th:include="include :: select2-css" />
</head>
<body>
<div class="main-content">
    <form class="form-horizontal" id="form-course-edit" th:object="${course}">
        <input name="cId"  type="hidden"  th:field="*{cId}" />
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课程名称：</label>
                    <div class="col-sm-8">
                        <input name="cName" placeholder="请输入用户名称" class="form-control" type="text" maxlength="30" th:field="*{cName}" required>
                    </div>
                </div>
            </div>

        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">课程可报名人数：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="cAvailablenum" placeholder="" class="form-control" type="text" maxlength="11" th:field="*{cAvailablenum}">
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课程类型：</label>
                    <select id="cTypeid" name="cTypeid"  placeholder="选择类型" class="form-control m-b">
                        <option value="" th:text="选择类型" >
                        <option th:each="coursetype:${coursetypes}" th:value="${coursetype.tId}" th:text="${coursetype.tName}" ></option>
                    </select>
                </div>
            </div>

                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">所在年级：</label>
                        <select id="gId" name="gId"  placeholder="选择年级" class="form-control">
                            <option value="" th:text="选择年级">
                            <option th:each="grade:${grades}" th:value="${grade.gId}" th:text="${grade.gName}" ></option>
                        </select>
                    </div>
                </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script type="text/javascript">
    var prefix = ctx + "system/course";

    $("#form-course-edit").validate({
        onkeyup: false,
        rules:{
            cName:{
                remote: {
                    url: prefix + "/checkcNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "cId": function() {
                            return $("#cId").val();
                        },
                        "cName": function() {
                            return $.common.trim($("#cName").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "cName":{
                remote: "课程已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-course-edit").serializeArray();
            var cName = $("input[name='cName']").val();
            var cAvailablenum = $("input[name='cAvailablenum']").val();
            var cTypeid = $("#cTypeid").val();
            var gId= $("#gId").val();
            data.push({"name": "cName", "value": cName});
            data.push({"name": "cAvailablenum", "value": cAvailablenum});
            data.push({"name": "cTypeid", "value": cTypeid});
            data.push({"name": "gId", "value": gId});
            $.operate.saveTab(prefix + "/edit", data);
        }
    }


    function doSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }



</script>
</body>
</html>